package jmine.tec.script.persistent.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Embeddable;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

import bancosys.tec.component.Documentation;

/**
 * Armazena dependências de injeção de scripts do hydra
 * 
 * @author lundberg
 */
@Embeddable
public class ScriptDependency implements Serializable {

    private String bean;

    private String variable;

    /**
     * Constructor
     */
    public ScriptDependency() {
        // OK
    }

    /**
     * Constructor
     * 
     * @param bean bean
     * @param variable variable
     */
    public ScriptDependency(String bean, String variable) {
        super();
        this.bean = bean;
        this.variable = variable;
    }

    /**
     * @return the bean
     */
    @Column(name = "BEAN", nullable = false)
    @Documentation("NOME DO BEAN A SER INJETADO NA BEANFACTORY")
    public String getBean() {
        return this.bean;
    }

    /**
     * @return the variable
     */
    @Column(name = "VARIABLE", nullable = false)
    @Documentation("NOME DA VARIAVEL DO SCRIPT QUE DEVE RECEBER O BEAN")
    public String getVariable() {
        return this.variable;
    }

    /**
     * @param bean the bean to set
     */
    public void setBean(String bean) {
        this.bean = bean;
    }

    /**
     * @param variable the variable to set
     */
    public void setVariable(String variable) {
        this.variable = variable;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(Object obj) {
        if (obj == null || !(obj instanceof ScriptDependency)) {
            return false;
        }
        ScriptDependency o = (ScriptDependency) obj;
        return new EqualsBuilder().append(this.bean, o.bean).append(this.variable, o.variable).isEquals();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        return new HashCodeBuilder().append(this.bean).append(this.variable).toHashCode();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return String.format("ScriptDependency bean: %s variable: %s", this.getBean(), this.getVariable());
    }
}
